<template>
	<view class="bgbox">
<!-- 		<view>
			<image src="../../static/image/bg.png" mode="" class="bgpic"></image>
		</view> -->

		<view class="story">
			<view class="story_title">
				<view>标题</view>
				<view>时间</view>
				<view>未读评论</view>
				<view>状态</view>
				<view>操作</view>
			</view>
			<scroll-view scroll-y @scrolltolower="scrollClick" class="story_list">
				<view class="story_item" v-for="item in list" :key="item.id">
					<view @click="toDetail(item)">{{item.title}}</view>
					<view>{{$u.timeFormat(item.createtime, 'yyyy-mm-dd hh:MM:ss')}}</view>
					<view>{{item.unread}}</view>
					<view>{{item.status==1?'通过':(item.status==2?'失败':'待审核')}}</view>
					<view>
						<view style="width: 100rpx;margin: 0 auto;">
							<u-button text="删除" type="error" size="mini" @click="shanchu(item.id)"></u-button>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>

	</view>
</template>

<script>
	import {
		storyListAPI,
		deletestoryAPI
	} from "@/api/api.js"
	export default {
		components: {},
		data() {
			return {
				list: [],
				page: 1

			}
		},
		onShow() {
			this.list = []
			this.page = 1
			this.getList()
		},
		methods: {
			// 监听滚动到底部
			scrollClick() {
				this.page++
				this.getList()
			},
			getList() {
				storyListAPI({
					clsss: 2,
					page: this.page
				}).then(res => {
					if ((res.data.data.rows).length == 0) {
						this.page--
						return
					}
					this.list = [...this.list, ...res.data.data.rows]
				})
			},
			toDetail(opt) {
				uni.navigateTo({
					url: "/pages/story/detail?id=" + opt.id + "&type=story"
				})
			},
			 async shanchu(id) {
			     try {
			         const response = await deletestoryAPI({ id });
			         uni.$u.toast(response.data.msg);
			 
			         // 手动更新 this.list
			         const index = this.list.findIndex(item => item.id === id);
			         if (index !== -1) {
			             this.list.splice(index, 1);
			         }
			     } catch (error) {
			         console.error("删除失败", error);
			     }
			 },


		}
	}
</script>
<style lang="scss" scoped>
	.bgbox {
		position: relative;		
		min-height: 100vh;
		background: url('../../static/image/bg.png') no-repeat;
		background-size: 100% 100%;
	}

	.bgpic {
		position: absolute;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		width: auto;
		height: auto;
		min-height: calc(100vh - 44px);
		z-index: 0;

	}

	.story {
		box-sizing: border-box;
		border-radius: 10rpx;
		box-sizing: border-box;
		width: 100%;
		padding: 0 20rpx;
		box-sizing: border-box;

		.story_title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 80rpx;
			background-color: #fff;
			&>view {
				width: 20%;
				text-align: center;
				font-size: 26rpx;
			}
		}

		.story_list {
			height: calc(100vh - 300rpx);
			overflow: auto;

			.story_item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #fff;
				height: 80rpx;
				font-size: 24rpx;
				margin-top: 4rpx;

				&>view {
					width: 20%;
					text-align: center;
				}
			}
		}
	}
</style>